package com.common.utils.JudgeUtils;

import com.common.utils.CommonException.CommonRuntimeException;
import com.common.utils.CommonException.ExceptionCodeEnum;

/**
 * @author bigboss
 */
public class JudgeUtils {

    public static ThrowExceptionFunction isTrue(Boolean message){
        return throwMessage ->{
            if( !message ){
                throw new CommonRuntimeException(ExceptionCodeEnum.SERVER_ERROR);
            }
        };
    }

    public static ThrowExceptionFunction isFalse(Boolean message){
        return isTrue(!message);
    }

    public static BranchExceptionHandle judge(Boolean message){
        return (trueHandle, falseHandle) -> {
            if( message ){
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    };

}
